package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import java.util.Locale;

import org.antlr.v4.runtime.misc.NotNull;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.AtomExpressionContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.StreamNameOrAliasContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.FieldExpressionContext;

/**
 * 字段表达式遍历 解析如s1.id这样的语法 S1既可以是流的名称，也可以是流的别名
 * 
 * 语法如下: fieldExpression : atomExpression (DOT columnName)* ;
 * 
 * 
 * @author zwd
 *
 */
public class FieldExpressionVisitor extends AbsCQLParserBaseVisitor<FieldExpressionContext> {

	/**
	 * 字段表达式解析结果
	 */
	private FieldExpressionContext context = null;

	public FieldExpressionVisitor() {
		context = new FieldExpressionContext();
	}

	@Override
	protected FieldExpressionContext defaultResult() {
		return context;
	}

	@Override
	public FieldExpressionContext visitAtomExpression(@NotNull AtomExpressionContext ctx) {
		AtomExpressionVisitor visitor = new AtomExpressionVisitor();
		context.setAtomExpression(visitor.visit(ctx));
		return context;
	}
	
	@Override
	public FieldExpressionContext visitStreamNameOrAlias(@NotNull StreamNameOrAliasContext ctx) {
		context.setStreamNameOrAlias(ctx.getText().toLowerCase(Locale.US));
        return context;
	}

}
